package com.jy.wms.controller;

import com.github.pagehelper.Page;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsCarrier;
import com.jy.wms.service.WmsCarrierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName: WmsCarrierController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author yjs
 * @Date Fri Aug 17 14:17:08 GMT+08:00 2018
 */
@RestController
@RequestMapping("/wmscarrier")
@Api(value = "/wmscarrier", description = "")
public class WmsCarrierController extends BaseController<WmsCarrierService,WmsCarrier> {

    @PostMapping(value = {"list", ""})
    @ApiOperation(value = "查询信息",response = JSONObject.class, notes = "查询信息")
    public @ResponseBody
    ResultPage<WmsCarrier> getWmsCarrier(@RequestBody WmsCarrier entity, HttpSession session) {
        Page<WmsCarrier> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class, notes = "删除信息")
    public @ResponseBody
    JsonResult deleteWmsCarrier(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增信息",response = JSONObject.class, notes = "新增信息")
    public @ResponseBody
    JSONObject addWmsCarrier(@RequestBody WmsCarrier entity) {
        JSONObject jsonObject=new JSONObject();
        try {
            WmsCarrier wmsCarrier=baseService.baseSelectByPrimaryMc(entity.getMc());
            if(wmsCarrier!=null){
                return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "承运商类别增加失败", "承运商类别名称不可重复", "");
            }
            entity.setId(UUIDUtils.uuid());
            baseService.baseInsert(entity);
        } catch (SucessException e) {
            jsonObject= SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "承运商类别增加成功", e.getMessage(), JSONObject.fromObject(entity).toString());
        } catch (ServiceException e) {
            e.printStackTrace();
            jsonObject= SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "承运商类别增加失败", e.getMessage(), "");
        } catch (Exception e) {
            e.printStackTrace();
            jsonObject= SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "承运商类别增加失败", "承运商类别增加失败", "");
        }
        return jsonObject;
    }

    @GetMapping(value = "getWmsCarrier/{id}")
    @ApiOperation(value = "查看单个信息",response = JSONObject.class, notes = "GET查看单个信息")
    public @ResponseBody WmsCarrier getWmsCarrierById(@PathVariable("id") String id) {
        WmsCarrier entity=baseService.baseSelectByPrimaryKey(id);
        return entity;
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑信息",response = JSONObject.class, notes = "编辑信息")
    public @ResponseBody
    JsonResult editWmsCarrier(@RequestBody WmsCarrier entity) {
        Integer flag=baseService.baseUpdateByPrimaryKeySelective(entity);
        return renderSuccess("修改成功");
    }
}
